package cn.edu.njnu.controller;

import cn.edu.njnu.pojo.Result;
import cn.edu.njnu.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/e-resource/api/v1.0")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class GroupController {
    private final GroupService groupService;

    /**
     * 根据组id查询用户id列表
     * @param groupId
     * @return
     */
    @GetMapping("/public/group/{groupId}/members")
    public Result getGroupMembers(@PathVariable("groupId") Integer groupId){
        return groupService.getMemberIdList(groupId);
    }

    /**
     * 根据用户id获取组信息
     * @param memberId
     * @return
     */
    @GetMapping("/public/member/{memberId}/groups")
    public Result getMemberGroupInfo(@PathVariable("memberId") Integer memberId){
        return groupService.getGroupInfo(memberId);
    }
}
